<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('销售列表')" />
</head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>条形码：<input type="text" name="barcode" oninput="codeChange(this)"/></li>
							<li>饰品名称：<input type="text" name="name"/></li>
							<li>门店：<input class="" type="text" onclick="selectDeptTree()" id="treeName" readonly="true"><input name="deptId" style="display: none;" id="treeId" th:value="${deptId}"/></li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()" id="searchId"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
				<!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:tSale:add">
					<i class="fa fa-plus"></i> 添加
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="system:tSale:edit">
					<i class="fa fa-edit"></i> 修改
				</a>-->
				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:tSale:remove">
					<i class="fa fa-remove"></i> 删除
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()">
						<i class="fa fa-download"></i> 导出
				 </a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:tSale:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:tSale:remove')}]];
        var prefix = ctx + "system/tSale";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                modalName: "销售",
		        showExport: true,
                showFooter: true,
                columns: [
                    {
		            checkbox: true
		        },
				{
					field : 'id', 
					title : '',
					visible: false
				},
				{
					field : 'barcode', 
					title : '条形码',
					sortable: false
				},
				{
					field : 'name', 
					title : '饰品名称',
					sortable: false
				},
				{
					field : 'deptName',
					title : '门店',
					sortable: false
				},
				{
					field : 'categoryName',
					title : '品类',
					sortable: false
				},
				{
					field : 'varietyName',
					title : '品种',
					sortable: false
				},
				{
					field : 'weight', 
					title : '重量(g)',
					sortable: false,
                    footerFormatter:function (value) {
                        var sumBalance = 0;
                        for (var i in value) {
                            sumBalance += parseFloat(value[i].weight);
                        }
                        return sumBalance.toFixed(2);
                    }
				},
				{
					field : 'labelprice', 
					title : '标签价格',
					sortable: false,
                    footerFormatter:function (value) {
                        var sumBalance = 0;
                        for (var i in value) {
                            sumBalance += parseFloat(value[i].labelprice);
                        }
                        return sumBalance.toFixed(2);
                    }
				},
				{
					field : 'indate', 
					title : '入库时间',
					sortable: false
				},
				{
					field : 'saleprice',
					title : '实收金额',
					sortable: false,
                    footerFormatter:function (value) {
                        var sumBalance = 0;
                        for (var i in value) {
                            sumBalance += parseFloat(value[i].saleprice);
                        }
                        return sumBalance.toFixed(2);
                    }
				},
				{
					field : 'saledate', 
					title : '销售时间',
					sortable: false,
                    formatter: function (value, row, index) {
                        return "<span style=\"color: #f8ac59\">"+row.saledate+"</span>";
                    }
				},
				{
					field : 'salesman', 
					title : '销售员',
					sortable: false,
                    formatter: function (value, row, index) {
                        return "<span style=\"color: #f8ac59\">"+row.salesman+"</span>";
                    }
				},
				{
					field : 'registrant', 
					title : '登记者',
					sortable: false,
                    formatter: function (value, row, index) {
                        return "<span style=\"color: #f8ac59\">"+row.registrant+"</span>";
                    }
				},{
					field : 'discount',
					title : '折扣率',
					sortable: false,
                    formatter: function (value, row, index) {
                        return "<span style=\"color: #f8ac59\">"+row.discount+"</span>";
                    }
				},
		        /*{
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }*/]
            };
            $.table.init(options);
        });

        function codeChange(obj) {
            var code = $(obj).val()
            $("#searchId").trigger("click");
        }

        /*用户管理-新增-选择部门树*/
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: ctx + "system/dept/selectDeptTree/" + deptId,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero) {
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }
        }
    </script>
</body>
</html>